package br.perfiman.service.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import br.ce.wcaquino.Validation.GeneralValidation;
import br.perfiman.dao.AbstractDAOService;
import br.perfiman.dao.CategoryDAOService;
import br.perfiman.exceptions.ErrorsConstants;
import br.perfiman.exceptions.RequiredFieldException;
import br.perfiman.model.Category;
import br.perfiman.service.CategoryService;

/**
 *
 * @author Wagner Costa
 * @since 27/12/2007
 * @version 1.0
 *
 */
@Stateless
public class CategoryServiceBean extends AbstractServiceBean<Category> implements CategoryService{
	@EJB(name="CategoryDAOService")
	protected CategoryDAOService dao;

	@Override
	public AbstractDAOService<Category> getDao() {
		return dao;
	}

	@Override
	public Category insert(Category entity) throws Exception {
		return super.insert(entity);
	}

	@Override
	public void remove(Category entity) throws Exception {
		super.remove(entity);
	}

	@Override
	public List<Category> retrieveAll() throws Exception {
		return super.retrieveAll();
	}

	@Override
	public Category retrieveById(Object id) throws Exception {
		return super.retrieveById(id);
	}

	@Override
	public Category update(Category entity) throws Exception {
		return super.update(entity);
	}

	@Override
	public void validateBussinessRules(Category entity, boolean isUpdate) {
		// TODO Auto-generated method stub

	}

	@Override
	public void validateInvalidFields(Category entity, boolean isUpdate) {
		// TODO Auto-generated method stub

	}

	@Override
	public void validateRequiredFields(Category entity, boolean isUpdate) {
		RequiredFieldException exception = new RequiredFieldException();
		if(GeneralValidation.isEmpty(entity.getName()))
			exception.add(getFormKey("name"), ErrorsConstants.REQUIRED);

		if(exception.hasErrors())
			throw exception;
	}
}
